package com.csd.interceptor;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.csd.helper.ActionResult;
import com.csd.helper.IConstant;
import com.csd.vo.UserVO;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

/**
 * 
 * Interceptor：未登录拦截器
 * @author csd
 * @version 1.0
 * 
 * <br> 修订时间：2010-1-7
 * <br> 修改原因：创建文件
 * <br> 修改人：刘世彬
 * 
 * <br> 
 * 
 */
public class UnloggedInterceptor implements Interceptor{

	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	public void init() {
		// TODO Auto-generated method stub
		
	}

	public String intercept(ActionInvocation invoker) throws Exception {
		HttpSession session = ServletActionContext.getRequest().getSession();
		if(session != null)
		{
			Object attribute = session.getAttribute(IConstant.userVO);
			if(attribute != null)
			{
				Object value = session.getValue(IConstant.userVO);
				if(value != null && value instanceof UserVO)
				{
					return invoker.invoke();
				}
			}
		}
		
		
		//抛出未登录异常
		return ActionResult.unlogged;
	}

}
